import java.util.Scanner;

public class Class2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] LR = new int[n][2];
        for (int i=0;i<n;i++){
            LR[i][0] = scanner.nextInt();
            LR[i][1] = scanner.nextInt();
        }
        for (int i=0;i<n;i++){
            int L= LR[i][0];
            int R = LR[i][1];

            int num = 0;
            for (int j=L;j<=R;j++){
                int Sn = 0;
                while (j>0){
                    Sn+= j%10;
                    j = j/10;
                }
                if (j%Sn==1)
                    num++;
            }
            System.out.println(num);
        }
    }
}
